/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:52:02 AM
 * To change this template use File | Settings | File Templates.
 */
import dk.brics.automaton.Automaton;
import java.util.*;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Regexp, InternalSchemaErrorException, Schema, Context

class MinusRegexp extends Regexp
{

    MinusRegexp(Element element, Schema schema)
    {
        Iterator iterator = element.getChildren().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element1 = (Element)iterator.next();
            if(!Schema.isDSDElement(element1))
                continue;
            exp1 = parse(element1, schema);
            break;
        } while(true);
        do
        {
            if(!iterator.hasNext())
                break;
            Element element2 = (Element)iterator.next();
            if(!Schema.isDSDElement(element2))
                continue;
            exp2 = parse(element2, schema);
            break;
        } while(true);
        if(exp2 == null)
            throw new InternalSchemaErrorException();
        else
            return;
    }

    public Element toXML(Context context)
    {
        return (new Element("minus", "http://www.brics.dk/DSD/2.0")).addContent(exp1.toXML(context)).addContent(exp2.toXML(context));
    }

    boolean match(String s, Context context)
    {
        return exp1.match(s, context) && !exp2.match(s, context);
    }

    Automaton toAutomaton(Context context)
    {
        Automaton automaton = exp1.toAutomaton(context).intersection(exp2.toAutomaton(context).complement());
        automaton.minimize();
        return automaton;
    }

    void addBoolexps(Context context, Set set)
    {
        exp1.addBoolexps(context, set);
        exp2.addBoolexps(context, set);
    }

    void getMentioned(Context context, Set set, List list)
    {
        exp1.getMentioned(context, set, list);
        exp2.getMentioned(context, set, list);
    }

    Regexp exp1;
    Regexp exp2;
}
